include(FindSWIG)
include(FindPythonLibs)
include(UseSWIG)

option(PYTHON_BINDINGS "Build python bindings via swig" ON)

if(PYTHON_BINDINGS AND SWIG_FOUND AND PYTHONLIBS_FOUND)
    INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../src)
    INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})

    SWIG_ADD_MODULE(ftdi python ftdi.i)
    SWIG_LINK_LIBRARIES(ftdi ${PYTHON_LIBRARIES})

    GET_FILENAME_COMPONENT(PYTHON_LIB_INSTALL ${PYTHON_LIBRARY} PATH)
    GET_FILENAME_COMPONENT(SITEPACKAGE ${PYTHON_LIB_INSTALL}/../site-packages ABSOLUTE)

    INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/_ftdi.so DESTINATION ${SITEPACKAGE})
    INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/ftdi.py DESTINATION ${SITEPACKAGE})

    message(STATUS "Building python bindings via swig. Will be installed under ${SITEPACKAGE}")
else(PYTHON_BINDINGS AND SWIG_FOUND AND PYTHONLIBS_FOUND)
    message(STATUS "Not building python bindings")
endif(PYTHON_BINDINGS AND SWIG_FOUND AND PYTHONLIBS_FOUND)
